package view.pane;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.util.Map;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import view.Gui;
import controller.GameState;
import controller.human.User;

@SuppressWarnings("serial")
public class VotingResultsPane extends JPanel {
	Gui gui;
	public VotingResultsPane(Gui guiParam, Map<User, User> votes, User killed) {
		this.gui = guiParam;
		this.setLayout(new GridLayout(3,1));
		JPanel votesPanel = new JPanel();
		votesPanel.setLayout(new GridLayout(votes.size(),1));
		
		for (Map.Entry<User, User> entry : votes.entrySet()) {
			votesPanel.add(new JLabel("" + entry.getKey().getName() + " voted " + 
					entry.getValue().getName()));
		}
		this.add(votesPanel);
		
		if (killed == null) {
			this.add(new JLabel("Nobody killed, equality"));
			this.add(new JButton(new AbstractAction("Done") {
				public void actionPerformed(ActionEvent arg0) {
					gui.changeState(GameState.Voting);
					gui.updatePane(new VotingPane(gui));
				}
			}));
		} else {
			this.add(new JLabel(killed.getName() + " was killed"));
			this.add(new JButton(new AbstractAction() {
				public void actionPerformed(ActionEvent arg0) {
					gui.updatePane(new MainPane(gui));
				}
			}));
		}
		
	
	}

}
